import {ACTION_TYPES} from '../action/ActionTypes'
import ErrorState from './ErrorState'

const INITIAL_STATE: ErrorState = {
  error: null,
}

function errorReducers(
  state: ErrorState = INITIAL_STATE,
  action: {type: string; [key: string]: any},
) {
  switch (action.type) {
    case ACTION_TYPES.ERROR_SET_STATE: {
      return {
        ...state,
        ...action.state,
      }
    }

    case ACTION_TYPES.ERROR_SET_ERROR: {
      return {
        ...state,
        error: action.error,
      }
    }

    default: {
      return {
        ...state,
      }
    }
  }
}

export {errorReducers}
